package com.cqc.mall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cqc.mall.api.CommonResult;
import com.cqc.mall.product.entity.InfoEntity;
import com.cqc.mall.product.service.InfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/test")
@Api(tags = "商品测试")
public class TestController {

    @Autowired
    private InfoService infoService;

    @GetMapping("/save")
    public CommonResult info() {
        InfoEntity infoEntity = new InfoEntity();
        infoEntity.setName("苹果");
        infoEntity.setPrice(BigDecimal.valueOf(22.1));

        return CommonResult.success(infoService.save(infoEntity));
    }


    @GetMapping("/all")
    public CommonResult<IPage<InfoEntity>> getAll() {
        Page<InfoEntity> page = new Page<>();
        page.setCurrent(1);
        page.setSize(10);
        IPage<InfoEntity> iPage = infoService.page(page, new QueryWrapper<InfoEntity>());
        return CommonResult.success(iPage);
    }


    @GetMapping("/get-by-id")
    public CommonResult<InfoEntity>getById(){
        InfoEntity infoEntity = infoService.getById(1);
        return CommonResult.success(infoEntity);
    }
}
